package com.umeng.share;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.text.TextUtils;

import com.jude.umengfamily.R;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;

/**
 * Created by heqiang on 2015/10/21.
 */
public class ShareManager {
    private static ShareManager instance = null;
    final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[]
            {
                    SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.SINA,
                    SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE
            };

    public static ShareManager getInstance(Context ctx) {
        if (instance == null) {
            instance = new ShareManager();
            instance.configPlatforms(ctx);
            com.umeng.socialize.utils.Log.LOG = true;
        }
        return instance;
    }

    /**
     * 配置分享平台参数</br>
     */
    private void configPlatforms(Context context) {
        PlatformConfig.setWeixin("wxe0425b0a1594fdbf", "4ae3b4b5120bd67701b07527be181e9d");
        //微信 appid appsecret
        PlatformConfig.setSinaWeibo("3303863983", "7d75080a915c6c4343e4825635c2348a");
        //新浪微博 appkey appsecret
        PlatformConfig.setQQZone("1104881392", "kMmFHpryRcDR3GFb");
        // QQ和Qzone appid appkey
    }

    /**
     * 根据不同的平台设置不同的分享内容</br>
     */
    public ShareAction shareContent(Activity context, String content, String targetUrl, String title, String imageUrl, UMShareListener listener) {
        ShareAction action = new ShareAction(context).setDisplayList(displaylist)
                .withText(content)
                .withTitle(title)
                .withTargetUrl(targetUrl)
                .setListenerList(listener);
        if (!TextUtils.isEmpty(imageUrl)) {
            action.withMedia(new UMImage(context, imageUrl));
        } else {
            action.withMedia(new UMImage(context, R.drawable.share_logo));
        }
        action.open();
        return action;
    }

    public ShareAction shareContentAction(Activity context, String content, String targetUrl, String title, String imageUrl, UMShareListener listener) {
        ShareAction action = new ShareAction(context).setDisplayList(displaylist)
                .withText(content)
                .withTitle(title)
                .withTargetUrl(targetUrl)
                .setListenerList(listener);
        if (!TextUtils.isEmpty(imageUrl)) {
            action.withMedia(new UMImage(context, imageUrl));
        }
        return action;
    }

    public void shareContent(SHARE_MEDIA media, Activity context, String content, String targetUrl, String title, String imageUrl, UMShareListener listener) {
        ShareAction action = new ShareAction(context).setPlatform(media)
                .withText(content)
                .withTitle(title)
                .withTargetUrl(targetUrl)
                .setListenerList(listener);
        if (!TextUtils.isEmpty(imageUrl)) {
            action.withMedia(new UMImage(context, imageUrl));
        }
        action.share();
    }


    public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
        UMShareAPI.get(activity).onActivityResult(requestCode, resultCode, data);
    }
}
